package com.shou.dao.impl;

import java.util.List;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.shou.CommonVar;
import com.shou.dao.CollectionDao;
import com.shou.dao.support.EnhancedRule;
import com.shou.entity.Collection;

@Repository
public class CollectionDaoImpl extends BaseDaoImpl<Collection> implements CollectionDao{

	@Override
	public List<Collection> queryList(Collection collectionQuery) {
		// TODO Auto-generated method stub
		EnhancedRule rule = new EnhancedRule();
		if(collectionQuery.getUseStatus() == null) {
			rule.add(Restrictions.eq("useStatus",CommonVar.USE_ONUSE));
		}
		else if(collectionQuery.getUseStatus() == CommonVar.USE_NOUSE) {
			rule.add(Restrictions.eq("useStatus",CommonVar.USE_NOUSE));
		}
		
		if(collectionQuery.getServeId()!= null) {			
			rule.add(Restrictions.eq("serveId",collectionQuery.getServeId()));
		}
		if(collectionQuery.getUserId()!=null) {
			rule.add(Restrictions.eq("userId",collectionQuery.getUserId()));
		}
		rule.addOrder(Order.desc("id"));
		return this.query(Collection.class, rule);
	}

}
